package com.maoye.ossp.biz.statement.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.hotent.base.api.query.QueryFilter;
import com.hotent.base.api.query.QueryOP;
import com.maoye.ossp.biz.brand.entity.Supplier;
import com.maoye.ossp.biz.brand.service.impl.SupplierServiceImpl;
import com.maoye.ossp.biz.statement.entity.StatementMainConsortium;
import com.maoye.ossp.biz.statement.entity.StatementMainDetail2;
import com.maoye.ossp.biz.statement.entity.StatementMainDetail4;
import com.maoye.ossp.biz.statement.service.StatementMainConsortiumService;
import com.maoye.ossp.biz.statement.service.StatementMainDetail2Service;
import com.maoye.ossp.biz.statement.service.StatementMainDetail4Service;
import com.maoye.ossp.common.entity.Page;
import com.maoye.ossp.common.web.BaseController;
import com.maoye.ossp.sys.org.util.UserUtils;

/**
 * 联营对账controller
 * @author yanzy
 *
 */
@Controller
@RequestMapping("/statement/mainConsortium")
public class StatementMainConsortiumController extends BaseController{
	
	@Resource
	private StatementMainConsortiumService statementMainConsortiumService;
	@Resource
	private StatementMainDetail2Service statementMainDetail2Service;
	@Resource
	private StatementMainDetail4Service statementMainDetail4Service;
	@Resource
	private SupplierServiceImpl supplierServiceImpl;
	
	
	/**
	 * 展示结算对账列表信息
	 * @param statementMainConsortium
	 * @param request
	 * @param model
	 * @return
	 * @author yanzy
	 * @data 2014年6月20日
	 */
	@RequestMapping(value = "/list")
	public String list(StatementMainConsortium statementMainConsortium,
			HttpServletRequest request, Model model){
		// 获取登陆用户Id
		Long userId = UserUtils.getCurrentUserId();
		// 根据当前用户Id 如果是供应商 获取用户获取供应商信息
		Supplier supplier = supplierServiceImpl.get(userId);
		QueryFilter queryFilter =getQuerFilter(request, statementMainConsortium);
		// 设置供应商编码
		if (supplier != null) {
			queryFilter.addFilter("supplierNo", supplier.getSupplierNo(),
					QueryOP.EQUAL);
		}	
		Page<StatementMainConsortium> page =statementMainConsortiumService.find(queryFilter);
		model.addAttribute("page", page);
		return resultPage("/biz/statement/statementMainConsortium/list", model,
				request);
	}
	
	/**
	 * 展示结算对账详细信息
	 * @param statementMainConsortium
	 * @param request
	 * @param model
	 * @return
	 * @author yanzy
	 * @data 2014年6月20日
	 */
	@RequestMapping(value = "/view")
	public String view(StatementMainConsortium statementMainConsortium,
			HttpServletRequest request, Model model){
		String id=statementMainConsortium.getId().toString();
		String billNo = request.getParameter("billNo");	
		//联营对账单
		StatementMainConsortium consortium =statementMainConsortiumService.get(id);
		//联营对账单-扣费明细
		List<StatementMainDetail2> detail2list = statementMainDetail2Service.getStatementMainDetail2ByBillNo(billNo);
		//联营对账单-主营成本/价内扣款明细
		List<StatementMainDetail4> detail4list = statementMainDetail4Service.getByBillNo(billNo);
		model.addAttribute("statementMainConsortium",consortium);
		model.addAttribute("statementMainDetail2List", detail2list);
		model.addAttribute("statementMainDetail4List", detail4list);
		return resultPage("/biz/statement/statementMainConsortium/view", model,
						request);
	}
	
	
	
	
	
	
	
	
}
